<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Check if an element is exists with jQuery</title>
<script type="text/javascript" src="../jquery-1.11.0.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		
		$("#buttonDiv1").click(function() {
			if ($("#div1").length) {
				alert("div1 existe");
			} else {
				alert("div1 n'existe pas");
			}
		});
		
		$("#buttonDiv2").click(function() {
			if ($("#div2").length) {
				alert("div2 existe");
			} else {
				alert("div2 n'existe pas");
			}
		});
		
	});
</script>
</head>
<body>
	<h1>jQuery check if an element exists</h1>
	<div id="div1">
		<b>This is DIV element which has an ide of "div1"</b>
	</div>
	<br/><br/>
	<input type='button' value='div1 exists?' id='buttonDiv1'>
	<input type='button' value='div2 exists?' id='buttonDiv2'>
	<br><br><a href="index.jsp">retour</a>
</body>
</html>